/*
 * File:   ReaderTest.cpp
 * Author: Guilherme Monteiro
 *
 */

#include "ReaderTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION(ReaderTest);

ReaderTest::ReaderTest() {
}

ReaderTest::~ReaderTest() {
}

void ReaderTest::setUp() {
}

void ReaderTest::tearDown() {
}

void ReaderTest::testReader() {
    string inputFilePath1 = "";
    try {
        Reader* reader1 = new Reader(inputFilePath1);
    }
    catch(InvalidFileException &ife) {
        string msg = "ERROR ==> Invalid file: " + inputFilePath1;
        if(strcmp(ife.what(), msg.c_str()) != 0) {
            CPPUNIT_ASSERT(false);
        }
    }
}

void ReaderTest::testReadPoints() {
    string inputFilePath = "../books/caracterizacao/metadados/entrada/image278.txt";
    Reader* reader1 = new Reader(inputFilePath);
    vector<CvPoint> points1 = reader1->readPoints();
    if (points1[0].x != 162 || points1[0].y != 2277) {
        CPPUNIT_ASSERT(false);
    }
    if(points1[1].x != 2316 || points1[1].y != 2862) {
        CPPUNIT_ASSERT(false);
    }
    
    string inputFilePath2 = "../books/estatisticas/metadados/entrada/image49.txt";
    Reader* reader2 = new Reader(inputFilePath2);
    vector<CvPoint> points2 = reader2->readPoints();
    if (points2[0].x != 18 || points2[0].y != 59) {
        CPPUNIT_ASSERT(false);
    }
    if( points2[1].x != 589 || points2[1].y != 287) {
        CPPUNIT_ASSERT(false);
    }
    if (points2[2].x != 18 || points2[2].y != 353) {
        CPPUNIT_ASSERT(false);
    }
    if( points2[3].x != 589 || points2[3].y != 660) {
        CPPUNIT_ASSERT(false);
    }
}


void ReaderTest::testReadCells() {
    string inputFilePath = "../books/caracterizacao/metadados/entrada/image278.txt";
    Reader* reader1 = new Reader(inputFilePath);
    vector<Cell> cells1 = reader1->readCells();
    
    if (cells1[0].leftUpper.x != 162 || cells1[0].leftUpper.y != 2277) {
        CPPUNIT_ASSERT(false);
    }
    if (cells1[0].rightBottom.x != 2316 || cells1[0].rightBottom.y != 2862) {
        CPPUNIT_ASSERT(false);
    }
    
    string inputFilePath2 = "../books/estatisticas/metadados/entrada/image49.txt";
    Reader* reader2 = new Reader(inputFilePath2);
    vector<Cell> cells2 = reader2->readCells();
    if (cells2[0].leftUpper.x != 18 || cells2[0].leftUpper.y != 59) {
        CPPUNIT_ASSERT(false);
    }
    if( cells2[0].rightBottom.x != 589 || cells2[0].rightBottom.y != 287) {
        CPPUNIT_ASSERT(false);
    }
    if (cells2[1].leftUpper.x != 18 || cells2[1].leftUpper.y != 353) {
        CPPUNIT_ASSERT(false);
    }
    if( cells2[1].rightBottom.x != 589 || cells2[1].rightBottom.y != 660) {
        CPPUNIT_ASSERT(false);
    }
}
